﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AgencyEntityLib.BaseEntity;
using FormControllers;
using Ecopsy.Tools;
using Ecopsy.DataTier;

/// <summary>
/// управление пользовтаелями
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ws_Securety : System.Web.Services.WebService
{
    private string sRoleList = "RoleList";
    public ws_Securety()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    /// <summary>
    /// полный список ролей системы
    /// </summary>
    /// <returns></returns>
    [WebMethod(EnableSession = true)]
    public RoleList GetRoleList()
    {
        ////список ролей
        if (!CacheTools.IsCacheObject(sRoleList))
        {
            RoleList r = new RoleList();
            r.Load();
            CacheTools.SetCacheObject(sRoleList, r); 
            return r;
        }
        return (RoleList)CacheTools.GetCacheObect(sRoleList);
    }

    /// <summary>
    /// Cписок ролей в которых учавствует товарищ
    /// </summary>
    /// <param name="Login"></param>
    /// <returns></returns>
    [WebMethod(EnableSession = true)]
    public RoleMemberList GetRoleMemberList(string Login)
    {
        RoleMemberList memb = null;
        if (!CacheTools.IsSessionCacheObject (Login+"MemList"))
        {
            memb = new RoleMemberList();
            memb.Login = Login;
            memb.Load();
            CacheTools.SetSessionCacheObject (Login + "MemList", memb); 
            return memb;
        }
        memb =(RoleMemberList)CacheTools.GetSessionCacheObect(Login + "MemList");
        memb.Reset();
        return memb;
    }

    [WebMethod(EnableSession = true)]
    public void  ResetCache(string Login)
    {
        CacheTools.ResetCache(sRoleList);
    }
    
}

